﻿package com.designoutput.elements
{
	import com.designoutput.enum.ElementType;
	import com.designoutput.utils.Unit;
	import com.designoutput.utils.UnitUtils;

	/**
	 * 
	 * <br>RoundRectElement -> BaseRectElement -> BaseElement ->Base
	 */	
	public class RoundRectElement extends BaseRectElement
	{
		private var radius:Number; //radius of the Round Rect 

		public function RoundRectElement()
		{
			super();
			radius=15;
		}
		
		override public function getClassName():String{
			return ElementType.RoundRectangleElement; 
		}

		public function getR():Number
		{
			return radius;
		}

		public function setR(nR:Number):void
		{
			radius = nR;
		}

		override protected function updateElement():void
		{
			super.updateElement();
			
			this.graphics.clear();

			if (useLine)
			{
				drawRoundRect(this, 0, 0, _width, _height, radius, this.lineColor, this.lineAlpha, this.lineSize);
			}
			if (useFill)
			{
				fillRoundRect(this, 0, 0, _width, _height, radius, this.fillColor, this.fillAlpha, useLine ? this.lineColor : undefined, this.lineAlpha, this.lineSize);
			}
		}
		
		override public function toXML():XML
		{
			var xmlNode:XML = super.toXML();
			xmlNode.@radius = UnitUtils.convert(radius, Unit.PIXELS, Unit.INCHES);
			return xmlNode;
		}

		override public function fromXML(xmlNode:XML):void
		{
			super.fromXML(xmlNode);
			radius = UnitUtils.convert(Number(xmlNode.@radius), Unit.INCHES, Unit.PIXELS);
		}
	}
}